import { Router, Route, Switch, Redirect } from 'react-router-dom'
import history from 'utils/history'
import React, { Component } from 'react'
import Login from './pages/Login'
import Layout from './pages/Layout'
import AuthRoute from 'components/AuthRoute'
// import { hasToken } from 'utils/storage'

class App extends Component {
  render() {
    return (
      <Router history={history}>
        <div className="app">
          <Switch>
            <Redirect exact from="/" to="/login"></Redirect>
            {/* <Route
              path="/layout"
              render={(props) => {
                // 判断是否有token
                if (hasToken()) {
                  // {...props} 批量进行父传子 将props 对象中所有的属性 都进行父传子传递
                  return <Layout {...props}></Layout>
                } else {
                  // 跳转到登录页 拦截请求
                  return <Redirect to="/login"></Redirect>
                }
              }}
            ></Route> */}
            <AuthRoute path="/layout" component={Layout}></AuthRoute>
            <Route path="/login" component={Login}></Route>
            {/* <Route path="/layout" component={Layout}></Route> */}
          </Switch>
        </div>
      </Router>
    )
  }
}

export default App
